#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[100005];

signed main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	sort(a + 1, a + n + 1);

	int ans = 0;
	if (a[n] > 0)
		ans += a[n];
	if (a[n - 1] > 0)
		ans += a[n - 1];
	cout << ans;
	return 0;
}
